package 剑指offer.Month7_07.day18;

public class 二叉树中和为某一值的路径_三_自己 {
    int count = 0;
    public int FindPath (TreeNode root, int sum) {
        // write code here
        if(root == null) return count;
        solve(root,root.val,sum);
        FindPath(root.left,sum);
        FindPath(root.right,sum);
        return count;
    }

    public void solve(TreeNode root,int num,int sum){
        if(num == sum){
            count++;
        }

        if(root.left != null) solve(root.left,num + root.left.val,sum);
        if(root.right != null) solve(root.right,num + root.right.val,sum);
    }
}
